<!DOCTYPE html>
<html>

	<head>
		<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="../../css/iuapmobile.um.css">
		<link rel="stylesheet" href="../../css/font-icons.css">
		<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css" />

		<style>
			.amap-touch-toolbar .amap-zoomcontrol {
				bottom: -30px;
				right: 0px;
			}
			
			.panel {
				background-color: #ddf;
				color: #333;
				border: 1px solid silver;
				box-shadow: 3px 4px 3px 0px silver;
				position: absolute;
				top: 10px;
				right: 10px;
				border-radius: 5px;
				overflow: hidden;
				line-height: 20px;
			}
			
			.mapInput {
				width: 250px;
				height: 25px;
				border: 0;
				background-color: white;
			}
		</style>

		<script src="../../js/summer.js"></script>
		<script src="../../js/jquery.min.js"></script>
		<script src="../../js/Frameworks/iuapmobile.frameworks.ui.js"></script>
		<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=bf5e7c7172c343df4547ecc206a8cfca">
			/*此处引用高德插件，须带上开发key,请自行替换  */
		</script>

	</head>

	<body>
		<div class="um-win" id="map">
			<div class="um-header">
				<h3>地图选点</h3>
				<a href="#" class="um-back">返回</a>
			</div>
			<div class="um-content">
				<div id="container"></div>
			</div>

			<div class="um-footer">
				<button class="btns" onclick="submits()">
		        	确认选点
		        </button>
			</div>
		</div>

		<script src="../../js/Myjs/Common.js"></script>
		<script>
			var pagevalue;
			var pagePara;
			summerready = function() {
				pagePara = summer.pageParam.data;
			}
			$(function() {
				//定位
				$('#container').parent().css('position', 'relative');
				var map, geolocation, scale, toolbar;
				//加载地图，调用浏览器定位服务
				map = new AMap.Map('container', {
					resizeEnable: true,
					zoom: 11,
				});
				map.plugin(['AMap.Geolocation', 'AMap.Scale', 'AMap.ToolBar'], function() { //添加定位控件
					geolocation = new AMap.Geolocation({ //定位设置
						enableHighAccuracy: true, //是否使用高精度定位，默认:true
						convert: true, //自动偏移坐标，偏移后的坐标为高德坐标，默认：true		 
						showCircle: true, //定位成功后用圆圈表示定位精度范围，默认：true
						timeout: 20000, //超过10秒后停止定位，默认：无穷大
						buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
						zoomToAccuracy: true, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
						buttonPosition: 'RB',
					});
					scale = new AMap.Scale(); //添加比例尺控件
					toolbar = new AMap.ToolBar(); //添加工具栏控件
					map.addControl(geolocation);
					map.addControl(scale);
					map.addControl(toolbar);
					geolocation.getCurrentPosition();

					AMap.event.addListener(geolocation, 'complete', function(data) {
						//addPoint(data.position.getLng(), data.position.getLat());
					}); //返回定位信息

				});

				var objMarker = [];
				//为地图注册click事件获取鼠标点击出的经纬度坐标
				var clickEventListener = map.on('click', function(e) {
					addPoint(e.lnglat.getLng(), e.lnglat.getLat());
				});

				//金纬度添加点
				var addPoint = function(Lngs, Lats) {
					map.remove(objMarker);
					//点击标记 
					var markers = [{ //标记位置		
						icon: 'http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png',
						position: [Lngs, Lats]
					}];
					markers.forEach(function(marker) {
						var marker = new AMap.Marker({
							map: map,
							icon: marker.icon,
							position: [marker.position[0], marker.position[1]],
							offset: new AMap.Pixel(-12, -36)
						});
						objMarker.push(marker);
					});
				}

				AMap.plugin('AMap.Geocoder', function() {
					var marker = new AMap.Marker({
						map: map,
						bubble: true
					});
					var geocoder = new AMap.Geocoder({
						city: "010" //城市，默认：“全国”
					});
					map.on('click', function(e) {
						geocoder.getAddress(e.lnglat, function(status, result) {
							if(status == 'complete') {
								console.log(e.lnglat);
								pagevalue = {
									formattedAddress: result.regeocode.formattedAddress, //中文地址
									citycode: result.regeocode.addressComponent.citycode, //3位城市编码
									addressCode: result.regeocode.addressComponent.adcode, //地区编码
									shen: result.regeocode.addressComponent.province, //省
									shi: result.regeocode.addressComponent.city, //市
									qu: result.regeocode.addressComponent.district, //区
									lat: e.lnglat.lat,
									lng: e.lnglat.lng
								};
								console.log(pagevalue);
							}
						})
					});
				});
			});

			function submits() {
				if(!pagevalue) {
					alerts("点击地图选择地点");
				}

				summer.execScript({
					winId: pagePara.id,
					script: "mapback('" + JSON.stringify(pagevalue) + "')"
				});
				summer.closeWin();
			}
		</script>
	</body>

</html>